﻿@using Website.CRUDServices
@using Website.Models.Styling
@using Location = Website.Models.Domain.Location
@model Website.Models.ViewModels.ListView<Activity>
@{
    this.ViewBag.Title = "Forretningsudvikling";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var Users = this.ViewData["Users"] as List<User>;
    var Locations = this.ViewData["Locations"] as List<Location>;
}

<div class="float-right smallMarginBottom">
    <input type="button" onclick="@string.Format("location.href = '{0}';", this.Url.Action("NewBusinessDevelopment"))" value="Opret ny" class="" />
</div>

<table class="tableView">
    <tr>
        @foreach (TableViewHeaderItem item in this.Model.Header.Items)
        {
            <td>
                @Html.Partial("~/Views/_Shared/TableViewHeader.cshtml", item)
            </td>
        }
        <td></td>
    </tr>
    @if (this.Model != null)
    {
        foreach (Activity act in this.Model.List)
        {
            User creator = Users.SingleOrDefault(x => x.ID == act.Creator);
            Locations = Locations.Where(x => x.ID == act.Location).ToList();
            Location location = Locations.Count() > 0 ? Locations[0] : null;
            <tr>
                <td>@string.Format("{0:dd-MM-yyyy}", act.TimeOfActivity)</td>
                <td> 
                    @if (location != null)
                    {
                        @location.Name
                    }

                </td>
                <td>
                    @if (act.Commentary.Length < 30)
                    {
                        @act.Commentary
                    }
                    else
                    {
                        @(string.Format("{0}...", act.Commentary.Substring(0, 30)))
                    }

                </td>
                <td>
                    @if (creator != null)
                    {
                        @creator.Name
                    }
                </td>
                <td><a href="@Url.Action("UpdateBusinessDevelopment", new { @Id = act.ID })">
                        <img src="@Url.Content("~/Content/ButtonIcons/tool_blue.png")" alt="Link"/></a></td>
            </tr>
        }
    }


    <tr>
        @Html.Partial("~/Views/_Shared/PagingArrows.cshtml", new PagingArrows { Action = "Index", TotalAmountOfColumns = 5, CurrentSkip = this.Model.Skip, CurrentTake = this.Model.Take, CurrentTotalRowCount = this.Model.TotalRows })
    </tr>
</table>